var app = getApp()
Page({
  data: {
    footer: {
      i_home: "../images/button1.png",
      i_tel: "../images/button2.png",
      i_chat: "../images/button4on.png",
      i_add: "../images/button5.png",
    },
    windowWidth: 375,
    windowHeight: 571,
    otherheight: 20,
    contentheight: 500,
    arraydetail: [],
    scrollTop: 0,
    scrollHeight: 0,
    pageIndex: 1,
    mpcateId: 0,
    searchkeyword: '',
    loadding: true,
    author: 'Lotus'
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.shopName,
      path: '/pages/index/productlist?fromInviteCode=' + app.globalData.myInviteCode,
      success: function (res) {
        //console.log("转发成功");
      }
    }
  },
  //获取商品列表
  getlist: function (e) {
    //console.log(e);
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/getcatelist&cateid=' + e,
      'cachetime': '30',
      success: function (res) {
        var goods_list = res.data.data.rlist;
        that.setData({
          arraydetail: goods_list
        })
      }
    })
  },
  //获取搜索的商品列表
  getsearchlist: function (e) {
    //console.log(e);
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/Searchlist&searchkeyword=' + e,
      'cachetime': '30',
      success: function (res) {
        var goods_list = res.data.data.rlist;
        that.setData({
          arraydetail: goods_list
        })
      }
    })
  },

  onLoad: function (options) {
    var that = this;
    //这里要非常注意，微信的scroll-view必须要设置高度才能监听滚动事件，所以，需要在页面的onLoad事件中给scroll-view的高度赋值
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollHeight: res.windowHeight
        });
      }
    });
    console.log(options.searchkeyword);
    var searchkeyword = options.searchkeyword;
    if(searchkeyword==undefined){
        that.getlist(options.cateId);
        
    }else{
     that.getsearchlist(searchkeyword);
    }
   
  }

})